﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using vudu.Logica.Fachada;
using vudu.Logica.Clases;
using vudu.Presentacion.Contrato.VU_05_Gestionar_Practicas_por_Materia;
using vudu.Presentacion.Presentador.VU_05_Gestionar_Practicas_por_Materia;

namespace vudu.Presentacion.Vista.VU_05_Gestionar_Practicas_por_Materia
{
    public partial class ModificarSeccionPractica : System.Web.UI.Page, IContratoModificarSeccionPractica
    {
        private PresentadorModificarSeccionPractica _presentador;

        #region PageConstructor

            private void Page_Init(object sender, EventArgs e)
            {
                _presentador = new PresentadorModificarSeccionPractica(this);
                if (!IsPostBack)
                { _presentador.LoadDdlMateria(); }
            }

            protected void Page_Load(object sender, EventArgs e)
            {

            }

        #endregion endPageConstructor

        protected void GridViewModify_SelectedIndexChanged(object sender, EventArgs e)
        {
            ddlMateria.Enabled = false;
            ddlSeccTeoria.Enabled = false;
            _presentador.LoadModifyModule(Convert.ToInt32(gridViewModify.SelectedRow.Cells[4].Text));
        }

        protected void GridViewModify_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gridViewModify.PageIndex = e.NewPageIndex;
            _presentador.LoadGridView();
        }

        protected void ddlMateria_onselectedindexchanged(object sender, EventArgs e)
        {
            labelStatus.Text = "";
            _presentador.UnLoadAllDdlSeccTeoria();
            _presentador.LoadDdlSeccTeoria();
        }

        protected void ddlSeccTeoria_onselectedindexchanged(object sender, EventArgs e)
        {
           // _presentador.UnLoadGridView();
            _presentador.LoadGridView();
            //_presentador.UnLoadDdlGeneric(ddlProfesor);
            //_presentador.LoadDdlProfesor();
        }

        protected void ddlProfesor_onselectedindexchanged(object sender, EventArgs e)
        {
            _presentador.LoadTableHorario();
        }

        #region HoraIniElements

        protected void ddlIniLun_onselectedindexchanged(object sender, EventArgs e)
        {
            _presentador.UnLoadDdlHoraFin(ddlFinLun, ddlSalonLun);
            _presentador.LoadDdlHoraFin(DdlFinLun, DdlIniLun);
            _presentador.SetHrsSelect();
        }

        protected void ddlIniMar_onselectedindexchanged(object sender, EventArgs e)
        {
            _presentador.UnLoadDdlHoraFin(ddlFinMar, ddlSalonMar);
            _presentador.LoadDdlHoraFin(DdlFinMar, DdlIniMar);
            _presentador.SetHrsSelect();
        }

        protected void ddlIniMie_onselectedindexchanged(object sender, EventArgs e)
        {
            _presentador.UnLoadDdlHoraFin(ddlFinMie, ddlSalonMie);
            _presentador.LoadDdlHoraFin(DdlFinMie, DdlIniMie);
            _presentador.SetHrsSelect();
        }

        protected void ddlIniJue_onselectedindexchanged(object sender, EventArgs e)
        {
            _presentador.UnLoadDdlHoraFin(ddlFinJue, ddlSalonJue);
            _presentador.LoadDdlHoraFin(DdlFinJue, DdlIniJue);
            _presentador.SetHrsSelect();
        }

        protected void ddlIniVie_onselectedindexchanged(object sender, EventArgs e)
        {
            _presentador.UnLoadDdlHoraFin(ddlFinVie, ddlSalonVie);
            _presentador.LoadDdlHoraFin(DdlFinVie, DdlIniVie);
            _presentador.SetHrsSelect();
        }

        #endregion endHoraIniElements

        #region HoraFinElements

        protected void ddlFinLun_onselectedindexchanged(object sender, EventArgs e)
        {
            _presentador.UnLoadDdlGeneric(ddlSalonLun);
            _presentador.SetHorarioForSearching(ddlIniLun, ddlFinLun, DdlSalonLun);
            _presentador.SetHrsSelect();
        }

        protected void ddlFinMar_onselectedindexchanged(object sender, EventArgs e)
        {
            _presentador.UnLoadDdlGeneric(ddlSalonMar);
            _presentador.SetHorarioForSearching(ddlIniMar, ddlFinMar, ddlSalonMar);
            _presentador.SetHrsSelect();
        }

        protected void ddlFinMie_onselectedindexchanged(object sender, EventArgs e)
        {
            _presentador.UnLoadDdlGeneric(ddlSalonMie);
            _presentador.SetHorarioForSearching(ddlIniMie, ddlFinMie, ddlSalonMie);
            _presentador.SetHrsSelect();
        }

        protected void ddlFinJue_onselectedindexchanged(object sender, EventArgs e)
        {
            _presentador.UnLoadDdlGeneric(ddlSalonJue);
            _presentador.SetHorarioForSearching(ddlIniJue, ddlFinJue, ddlSalonJue);
            _presentador.SetHrsSelect();
        }

        protected void ddlFinVie_onselectedindexchanged(object sender, EventArgs e)
        {
            _presentador.UnLoadDdlGeneric(ddlSalonVie);
            _presentador.SetHorarioForSearching(ddlIniVie, ddlFinVie, ddlSalonVie);
            _presentador.SetHrsSelect();
        }

        #endregion endHoraFinElements

        #region SalonElements

        protected void ddlSalonLun_onselectedindexchanged(object sender, EventArgs e)
        {
            _presentador.SetHrsSelect();
        }

        protected void ddlSalonMar_onselectedindexchanged(object sender, EventArgs e)
        {
            _presentador.SetHrsSelect();
        }

        protected void ddlSalonMie_onselectedindexchanged(object sender, EventArgs e)
        {
            _presentador.SetHrsSelect();
        }

        protected void ddlSalonJue_onselectedindexchanged(object sender, EventArgs e)
        {
            _presentador.SetHrsSelect();
        }

        protected void ddlSalonVie_onselectedindexchanged(object sender, EventArgs e)
        {
            _presentador.SetHrsSelect();
        }

        #endregion endSalonElements

        protected void btnBackPractica_Click(object sender, EventArgs e)
        {
            if (!tableHorario.Visible)
            { Response.Redirect("../HomePages/HomeEscuela.aspx"); }
            else
            {
                btnNextPractica.Visible = false;
                btnBackPractica.Visible = false;
                btnBackPracticaCenter.Visible = true;
                ddlSeccTeoria.Enabled = true;
                ddlMateria.Enabled = true;
                gridViewModify.Visible = true;
                _presentador.UnLoadAllDdlProfesor();
                _presentador.UnLoadHorario();
            }
        }
        protected void btnNextPractica_Click(object sender, EventArgs e)
        {
            _presentador.ModificarSeccionPractica();
        }

        #region GUIElements

            public Label LabelEscuela { get { return labelEscuela; } }
            public Label LabelStatus { get { return labelStatus; } }

            public Label LabelOMateria { get { return labelOMateria; } }
            public Label LabelMateria { get { return labelMateria; } }
            public DropDownList DdlMateria { get { return ddlMateria; } }

            public Label LabelOSeccTeoria { get { return labelOSeccTeoria; } }
            public Label LabelSeccTeoria { get { return labelSeccTeoria; } }
            public DropDownList DdlSeccTeoria { get { return ddlSeccTeoria; } }
            public Label LabelHrsReq { get { return labelHrsReq; } }
            public Label LabelNumHrsReq { get { return labelNumHrsReq; } }

            public Label LabelOProfesor { get { return labelOProfesor; } }
            public Label LabelProfesor { get { return labelProfesor; } }
            public DropDownList DdlProfesor { get { return ddlProfesor; } }
            public Label LabelOHrsSelect { get { return labelOHrsSelect; } }
            public Label LabelHrsSelect { get { return labelHrsSelect; } }
            public Label LabelNumHrsSelect { get { return labelNumHrsSelect; } }

            public Table TableHorario { get { return tableHorario; } }

            public DropDownList DdlIniLun { get { return ddlIniLun; } }
            public DropDownList DdlIniMar { get { return ddlIniMar; } }
            public DropDownList DdlIniMie { get { return ddlIniMie; } }
            public DropDownList DdlIniJue { get { return ddlIniJue; } }
            public DropDownList DdlIniVie { get { return ddlIniVie; } }

            public DropDownList DdlFinLun { get { return ddlFinLun; } }
            public DropDownList DdlFinMar { get { return ddlFinMar; } }
            public DropDownList DdlFinMie { get { return ddlFinMie; } }
            public DropDownList DdlFinJue { get { return ddlFinJue; } }
            public DropDownList DdlFinVie { get { return ddlFinVie; } }

            public DropDownList DdlSalonLun { get { return ddlSalonLun; } }
            public DropDownList DdlSalonMar { get { return ddlSalonMar; } }
            public DropDownList DdlSalonMie { get { return ddlSalonMie; } }
            public DropDownList DdlSalonJue { get { return ddlSalonJue; } }
            public DropDownList DdlSalonVie { get { return ddlSalonVie; } }


            public GridView GridViewModify { get { return gridViewModify; } }    

            public Button BtnNextPractica { get { return btnNextPractica; } }
            public Button BtnBackPractica { get { return btnBackPractica; } }
            public Button BtnBackPracticaCenter { get { return btnBackPracticaCenter; } }

            public HttpSessionState Sesion { get { return Session; } }

            public void Redirect(string ruta) { Response.Redirect(ruta); }

        #endregion GUIElements
    }
}